package com.itheima.reggie.controller;


import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.entity.User;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 提交订单
     *
     * @param orders
     * @param session
     * @return
     */
    @PostMapping("/submit")
    public R add(@RequestBody Orders orders, HttpSession session) {
        //调用service
        User user = (User) session.getAttribute("user");
        int rows = orderService.add(orders, user);

        if (rows > 0) {
            return R.success("订单提交成功！");
        } else {
            return R.error("订单提交成功！");
        }
    }
}
